import java.nio.ByteBuffer;


public class PacketConstructor {

	public PacketConstructor()
	{

	}

	/*
	 * Keep Alive packet
	 */
	public String[][] parsePacket00(byte[] packet)
	{
		ByteBuffer bb = ByteBuffer.allocate(packet.length);
		
		bb.put(packet);
		bb.rewind();
		System.out.println("Bytbyffer : "+bb.position()+ " "+bb.remaining());
		
		String[][] ret = new String[2][3];
		ret[0][0] = Integer.toHexString(bb.get());
		ret[0][1] = "Keep Alive";
		ret[0][2] = "byte";

		ret[1][0] = String.valueOf(bb.getInt());
		ret[1][1] = "Keep-Alive ID";
		ret[1][2] = "int";

		return ret;
	}
	
	/*
	 * Login request packet
	 */
	public String[][] parsePacket01(byte[] packet)
	{
		ByteBuffer bb = ByteBuffer.allocate(packet.length);
		String[][] ret = new String[9][3];
		short strLength;
		
		bb.put(packet);
		bb.rewind();
		System.out.println("Bytbyffer : "+bb.position()+ " "+bb.remaining());
		
		System.out.println("Login request : "+bb.capacity());
		System.out.println("getbyte "+Integer.toHexString(bb.get(bb.position())));
		ret[0][0] = Integer.toHexString(bb.get());
		ret[0][1] = "Login Request";
		ret[0][2] = "byte";

		System.out.println("getint "+bb.getInt(bb.position()));
		ret[1][0] = String.valueOf(bb.getInt());
		ret[1][1] = "Protocol Version";
		ret[1][2] = "int";
		
		strLength = bb.getShort();
		ret[2][0] = new String(packet, bb.position(), strLength);
		bb.position(bb.position() + 2 + strLength);
		ret[2][1] = "Username";
		ret[2][2] = "string";
		
		strLength = bb.getShort();
		ret[3][0] = new String(packet, bb.position(), strLength);
		bb.position(bb.position() + 2 + strLength);
		ret[3][1] = "Not used";
		ret[3][2] = "string";
		
		ret[4][0] = String.valueOf(bb.getInt());
		ret[4][1] = "Not used";
		ret[4][2] = "int";
		
		ret[5][0] = String.valueOf(bb.getInt());
		ret[5][1] = "Not used";
		ret[5][2] = "int";
		
		ret[6][0] = Integer.toHexString(bb.get());
		ret[6][1] = "Not used";
		ret[6][2] = "byte";
		
		ret[7][0] = Integer.toHexString(bb.get());
		ret[7][1] = "Not used";
		ret[7][2] = "byte";
		
		ret[8][0] = Integer.toHexString(bb.get());
		ret[8][1] = "Not used";
		ret[8][2] = "byte";

		return ret;
	}
	
	private String getString(byte[] b, int firstB, int length)
	{
		
		return "";
	}
}
